package com.jiuyou.clientController.engineering;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.engineering.domain.Engineering;
import com.ruoyi.engineering.service.IEngineeringService;
import com.ruoyi.enterprise.service.IEnterpriseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工程信息Controller
 *
 * @author ruoyi
 * @date 2025-05-07
 */
@RestController
@RequestMapping("/client/engineering")
public class ClientEngineeringController extends BaseController
{
    @Autowired
    private IEngineeringService engineeringService;

    @Autowired
    private IEnterpriseService enterpriseService;

    /**
     * 查询所有
     * */
    @GetMapping("/listAll")
    public AjaxResult listAll(Engineering engineering)
    {
        List<Engineering> list = engineeringService.selectEngineeringList(engineering);
        return AjaxResult.success(list);
    }

    /**
     * 查询工程信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Engineering engineering)
    {
        startPage();
        List<Engineering> list = engineeringService.selectEngineeringList(engineering);
        return getDataTable(list);
    }

    /**
     * 导出工程信息列表
     */
    @Log(title = "工程信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Engineering engineering)
    {
        List<Engineering> list = engineeringService.selectEngineeringList(engineering);
        ExcelUtil<Engineering> util = new ExcelUtil<Engineering>(Engineering.class);
        return util.exportExcel(list, "工程信息数据");
    }

    /**
     * 获取工程信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(engineeringService.selectEngineeringById(id));
    }

    /**
     * 新增工程信息
     */
    @Log(title = "工程信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Engineering engineering)
    {
        return toAjax(engineeringService.insertEngineering(engineering));
    }

    /**
     * 修改工程信息
     */
    @Log(title = "工程信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Engineering engineering)
    {
        engineering.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(engineeringService.updateEngineering(engineering));
    }

    /**
     * 删除工程信息
     */
    @Log(title = "工程信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(engineeringService.logicDeleteEngineering(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
